package com.dacong;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.ComputerSystem;
import oshi.hardware.HardwareAbstractionLayer;

import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


public class Main extends Application {

    String baseUrl = "http://124.222.60.59:8080";

    String token;

    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(5);
    ScheduledExecutorService tongjiService = Executors.newScheduledThreadPool(1);

    public static void main(String[] args) {
        Application.launch(args);
    }

    /**
     * 登录场景
     */
    Scene login;

    /**
     * 主业务场景
     */
    Scene main;

    /**
     * 购买ck弹窗
     */
    Dialog<ButtonType> ckDialog = new Dialog<>();
    TextField ckNumField = new TextField();
    TextField codeField = new TextField();

    /**
     * 购买店铺弹窗
     */
    Dialog<ButtonType> slinkDialog = new Dialog<>();

    TextField slinkNumField = new TextField();

    /**
     * 日志组件
     */
    TextArea textArea;

    /**
     * 激活状态
     */
    Boolean active = true;

    /**
     * 停止标记
     */
    Boolean stopFlag = false;

    /**
     * 延时时间
     */
    Long yanshi = 4000L;

    Long yanghaoyanshi = 2000L;

    String usernameStr;

    Date expireTime;

    BigDecimal profile = BigDecimal.ZERO;

    Integer baoliuzijin;

    Integer danliangshezhi;

    @Override
    public void stop() throws Exception {
        super.stop();
        System.out.println("点击关闭");
        Platform.exit();
        System.exit(0);
    }

    @Override
    public void start(Stage stage) throws Exception {

        ThreadUtil.execute(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        String s = HttpUtil.get(baseUrl+"/api/access/" + getMachineCode());
                        JSONObject entries = JSONUtil.parseObj(s);
                        expireTime = entries.getJSONObject("data").getDate("expireTime");
//                        expireTime = DateUtil.parse("2025-03-31 23:59:59");
                        int compare = DateUtil.compare(DateUtil.date(), expireTime);
                        if (compare == -1){
                            active = true;
                        }
                        ThreadUtil.sleep(5000);
                    }catch (Exception e){
                        e.printStackTrace();
                    }

                }
            }
        });


        loginSecen(stage);
        buyCk();
        buySlink();

        CheckBox yanghao = new CheckBox("自动养号");
        CheckBox xiadan = new CheckBox("自动下单");
        CheckBox fuhuo = new CheckBox("自动复活");
        CheckBox shensuCheck = new CheckBox("自动申诉");
        CheckBox tuikuanCheck = new CheckBox("自动退款");


        Label zijinyuzhiLabel = new Label("保留资金");
        TextField zijinyuzhiField = new TextField();
        zijinyuzhiField.textProperty().addListener((observable, oldValue, newValue) -> {
            if (!newValue.matches("\\d*")){
                zijinyuzhiField.setText(oldValue);
            }
        });
        TextField danliangField = new TextField();
        danliangField.textProperty().addListener((observable, oldValue, newValue) -> {
            if (!newValue.matches("\\d*")){
                danliangField.setText(oldValue);
            }
        });

        FlowPane settingFlow = new FlowPane();
        settingFlow.setHgap(10);
        settingFlow.setPadding(new Insets(10,10,10,10));
        settingFlow.getChildren().add(zijinyuzhiLabel);
        settingFlow.getChildren().add(zijinyuzhiField);

        Button start = new Button("开始");
        start.setMinWidth(100f);
        start.setMaxWidth(100f);
        Button stop = new Button("停止");
        stop.setMinWidth(100f);
        stop.setMaxWidth(100f);
        Button buyCk = new Button("CK租用");
        buyCk.setMinWidth(100f);
        buyCk.setMaxWidth(100f);
        Button buySlink = new Button("店铺购买");
        buySlink.setMinWidth(100f);
        buySlink.setMaxWidth(100f);



        TextArea textArea = new TextArea();
        textArea.setPadding(new Insets(10,10,10,10));
        textArea.setEditable(false);
        textArea.setWrapText(true);
        textArea.textProperty().addListener((observable, oldValue, newValue) -> {
            textArea.setScrollTop(Double.MAX_VALUE); // 滚动到底部
        });

        VBox vBox = new VBox();
        FlowPane checkflowPane = new FlowPane();
        checkflowPane.setHgap(10);
        checkflowPane.setPadding(new Insets(10,10,10,10));

        checkflowPane.getChildren().add(yanghao);
        checkflowPane.getChildren().add(xiadan);
        checkflowPane.getChildren().add(fuhuo);
        checkflowPane.getChildren().add(shensuCheck);
        checkflowPane.getChildren().add(tuikuanCheck);

        FlowPane buttonFlowPane = new FlowPane();
        buttonFlowPane.setHgap(10);
        buttonFlowPane.setPadding(new Insets(10,10,10,10));
        buttonFlowPane.getChildren().add(start);
        buttonFlowPane.getChildren().add(stop);
        buttonFlowPane.getChildren().add(buyCk);
        buttonFlowPane.getChildren().add(buySlink);

        vBox.getChildren().add(checkflowPane);
        vBox.getChildren().add(settingFlow);
        vBox.getChildren().add(buttonFlowPane);

        vBox.setVgrow(textArea, Priority.ALWAYS);


        GridPane tongji = new GridPane();
        tongji.setAlignment(Pos.CENTER_LEFT);
        tongji.setHgap(10);
        tongji.setVgap(10);

        Label yanghaoTongji = new Label("养号数据");
        Label yanghaoTongji1 = new Label("准备中：");
        yanghaoTongji1.setMinWidth(80);
        Label yanghaoTongji2 = new Label("养号中：");
        yanghaoTongji2.setMinWidth(80);
        Label yanghaoTongji3 = new Label("养号完成：");
        yanghaoTongji3.setMinWidth(80);

        Label dingdantongji = new Label("订单数据");
        Label dingdanzhunbeizhong = new Label("准备中");
        Label dingdantongji1 = new Label("已下单：");
        Label dingdantongji2 = new Label("申诉中：");
        Label dingdantongji3 = new Label("退款中：");

        Label today = new Label("今日数据");
        Label todayYanghaoLebel = new Label("今日养号");
        Label todayXiadanLebel = new Label("今日下单");
        Label todayPeifuLebel = new Label("今日赔付");
        Label todayTuikuanLebel = new Label("今日退款");

        Label yue = new Label("当前余额：");
        Label guzhi = new Label("账号估值：");

        tongji.add(yanghaoTongji,0,0,1,1);
        tongji.add(yanghaoTongji1,1,0,1,1);
        tongji.add(yanghaoTongji2,1,1,1,1);
        tongji.add(yanghaoTongji3,1,2,1,1);


        tongji.add(dingdantongji,2,0,1,1);
        tongji.add(dingdanzhunbeizhong,3,0,1,1);
        tongji.add(dingdantongji1,3,1,1,1);
        tongji.add(dingdantongji2,3,2,1,1);
        tongji.add(dingdantongji3,3,3,1,1);

        tongji.add(today,4,0,1,1);
        tongji.add(todayYanghaoLebel,5,0,1,1);
        tongji.add(todayXiadanLebel,5,1,1,1);
        tongji.add(todayPeifuLebel,5,2,1,1);
        tongji.add(todayTuikuanLebel,5,3,1,1);

        tongji.add(yue,6,0,1,1);
        tongji.add(guzhi,6,1,1,1);

        vBox.getChildren().add(tongji);
        vBox.getChildren().add(textArea);
        main = new Scene(vBox);


        if (StrUtil.isNotBlank(token)){
            stage.setScene(main);
        }else{
            stage.setScene(login);
        }

        stage.setTitle("魔童V1.0");
        stage.getIcons().add(new Image("image/icon.jpg"));
        stage.setWidth(600);
        stage.setHeight(400);
        stage.setResizable(false);
        stage.show();

        start.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                String zijin = zijinyuzhiField.getText();
                if (StrUtil.isNotBlank(zijin)){
                    baoliuzijin = Integer.parseInt(zijin);
                }else {
                    baoliuzijin = null;
                }
                String danliang = danliangField.getText();
                if (StrUtil.isNotBlank(danliang)){
                    danliangshezhi = Integer.parseInt(danliang);
                }else {
                    danliangshezhi = null;
                }
                stopFlag = false;
                start.setDisable(true);
                start.setText("执行中");
                yanghao.setDisable(true);
                xiadan.setDisable(true);
                fuhuo.setDisable(true);
                shensuCheck.setDisable(true);
                tuikuanCheck.setDisable(true);

                zijinyuzhiField.setDisable(true);
                danliangField.setDisable(true);

                System.out.println(yanghao.isSelected());
                System.out.println(fuhuo.isSelected());
                System.out.println(xiadan.isSelected());
                System.out.println(shensuCheck.isSelected());
                System.out.println(tuikuanCheck.isSelected());
                executorService = Executors.newScheduledThreadPool(5);

                if (yanghao.isSelected()) {
                    executorService.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            try{
                                Map<String,String> param = new HashMap<>();
                                param.put("action","yanghao");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                Integer code = jsonObject.getInt("code");
                                String data = jsonObject.getStr("data");
                                log(textArea,data);
                            }catch (Exception e){
                                e.printStackTrace();
                                log(textArea,e.toString());
                            }

                        }
                    },1,30,TimeUnit.SECONDS);
                }

                if (fuhuo.isSelected()) {
                    executorService.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            try{
                                Map<String,String> param = new HashMap<>();
                                param.put("action","fuhuo");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                Integer code = jsonObject.getInt("code");
                                String data = jsonObject.getStr("data");
                                if (StrUtil.isNotBlank(data)){
                                    log(textArea,data);
                                }

                            }catch (Exception e){
                                e.printStackTrace();
                                log(textArea,e.toString());
                            }


                        }
                    },1,30,TimeUnit.SECONDS);
                }

                if (xiadan.isSelected()) {
                    executorService.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            try{

                                Map<String,String> param = new HashMap<>();
                                param.put("action","xiadan");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                Integer code = jsonObject.getInt("code");
                                String data = jsonObject.getStr("data");
                                if (StrUtil.isNotBlank(data)){
                                    log(textArea,data);
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                                log(textArea,e.toString());
                            }

                        }
                    },1,30,TimeUnit.SECONDS);

                }

                if (shensuCheck.isSelected()) {
                    executorService.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            try{
                                Map<String,String> param = new HashMap<>();
                                param.put("action","shensu");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                Integer code = jsonObject.getInt("code");
                                String data = jsonObject.getStr("data");
                                if (StrUtil.isNotBlank(data)){
                                    log(textArea,data);
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                                log(textArea,e.toString());
                            }

                        }
                    },1,30, TimeUnit.SECONDS);
                }

                if (tuikuanCheck.isSelected()) {
                    executorService.scheduleAtFixedRate(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                Map<String,String> param = new HashMap<>();
                                param.put("action","tuikuan");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                Integer code = jsonObject.getInt("code");
                                String data = jsonObject.getStr("data");
                                if (StrUtil.isNotBlank(data)){
                                    log(textArea,data);
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                                log(textArea,e.toString());
                            }

                        }
                    },1,30,TimeUnit.SECONDS);
                }


            }
        });

        stop.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                stopFlag = true;
                executorService.shutdownNow();
                start.setText("开始");
                start.setDisable(false);
                yanghao.setDisable(false);
                xiadan.setDisable(false);
                fuhuo.setDisable(false);
                shensuCheck.setDisable(false);
                tuikuanCheck.setDisable(false);
                zijinyuzhiField.setDisable(false);
                danliangField.setDisable(false);

            }
        });

        buyCk.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                // 显示对话框并等待结果
                ckDialog.showAndWait().ifPresent(response -> {
                    if (response == ButtonType.OK) {

                        Map<String,Object> param = new HashMap<>();
                        param.put("action","buyCk");
                        param.put("token",token);
                        param.put("num",Integer.parseInt(ckNumField.getText()));
                        HttpResponse httpResponse = HttpUtil.createPost(baseUrl + "/api/action")
                                .body(JSONUtil.toJsonStr(param))
                                .execute();

                        JSONObject jsonObject = JSONUtil.parseObj(httpResponse.body());
                        Integer code = jsonObject.getInt("code");
                        String data = jsonObject.getStr("data");
                        if (StrUtil.isNotBlank(data)){
                            log(textArea,data);
                        }

                    }
                });
            }
        });

        buySlink.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                slinkDialog.showAndWait().ifPresent(response -> {
                    if (response == ButtonType.OK) {
                        Map<String,Object> param = new HashMap<>();
                        param.put("action","buySlink");
                        param.put("token",token);
                        param.put("num",Integer.parseInt(slinkNumField.getText()));
                        HttpResponse httpResponse = HttpUtil.createPost(baseUrl + "/api/action")
                                .body(JSONUtil.toJsonStr(param))
                                .execute();

                        JSONObject jsonObject = JSONUtil.parseObj(httpResponse.body());
                        Integer code = jsonObject.getInt("code");
                        String data = jsonObject.getStr("data");
                        if (StrUtil.isNotBlank(data)){
                            log(textArea,data);
                        }
                    }
                });
            }
        });

        tongjiService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                try{
                    ThreadUtil.execAsync(new Callable<Object>() {
                        @Override
                        public Object call() throws Exception {
                            if (StrUtil.isNotBlank(token)){

                                Map<String,String> param = new HashMap<>();
                                param.put("action","tongji");
                                param.put("token",token);
                                HttpResponse response = HttpUtil.createPost(baseUrl + "/api/action")
                                        .body(JSONUtil.toJsonStr(param))
                                        .execute();

                                JSONObject jsonObject = JSONUtil.parseObj(response.body());
                                JSONObject data = jsonObject.getJSONObject("data");

                                String yanghao = data.getStr("yanghao");
                                String yanghaoing = data.getStr("yanghaoing");
                                String yanghaoFinish = data.getStr("yanghaoFinish");
                                String yixiadan = data.getStr("yixiadan");
                                String shensuzhong = data.getStr("shensuzhong");
                                String tuikuanzhong = data.getStr("tuikuanzhong");
                                String zhunbeizhong = data.getStr("zhunbeizhong");
                                String todayYanghao = data.getStr("todayYanghao");
                                String todayXiadan = data.getStr("todayXiadan");
                                String todayPeifu = data.getStr("todayPeifu");
                                String todaytuikuan = data.getStr("todaytuikuan");
                                String profile = data.getStr("profile");
                                String guzhi1 = data.getStr("guzhi");

                                Platform.runLater(()->{
                                    yanghaoTongji1.setText("准备中："+yanghao);
                                    yanghaoTongji2.setText("养号中："+yanghaoing);
                                    yanghaoTongji3.setText("养号完成："+yanghaoFinish);

                                    dingdanzhunbeizhong.setText("准备中："+zhunbeizhong);
                                    dingdantongji1.setText("已下单："+yixiadan);
                                    dingdantongji2.setText("申诉中："+shensuzhong);
                                    dingdantongji3.setText("退款中："+tuikuanzhong);

                                    todayYanghaoLebel.setText("今日养号："+todayYanghao);
                                    todayXiadanLebel.setText("今日下单："+todayXiadan);
                                    todayPeifuLebel.setText("今日赔付："+todayPeifu);
                                    todayTuikuanLebel.setText("今日退款："+todaytuikuan);

                                    yue.setText("当前余额："+profile);
                                    guzhi.setText("账号估值："+guzhi1);
                                });
                            }
                            return null;
                        }
                    });

                }catch (Exception e){
                    e.printStackTrace();
                    log(textArea,e.toString()+e.getMessage());
                }
            }
        },1,10,TimeUnit.SECONDS);
    }

    public void loginSecen(Stage stage){

        // 创建布局
        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));

        // 创建场景
        login = new Scene(grid, 300, 275);

        // 添加标题
        Text scenetitle = new Text("欢迎登录");
        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
        grid.add(scenetitle, 0, 0, 2, 1);

        // 添加用户名标签
        Label userName = new Label("用户名:");
        grid.add(userName, 0, 1);

        // 添加用户名输入框
        TextField userTextField = new TextField();
        grid.add(userTextField, 1, 1);

        // 添加密码标签
        Label pw = new Label("密码:");
        grid.add(pw, 0, 2);

        // 添加密码输入框
        PasswordField pwBox = new PasswordField();
        grid.add(pwBox, 1, 2);

        // 添加密码标签
        Label code = new Label("二次验证码:");
        grid.add(code, 0, 3);

        // 添加密码输入框
        TextField codeField = new TextField();
        grid.add(codeField, 1, 3);

        // 添加密码标签
        Label machineCode = new Label("机器码:");
        grid.add(machineCode, 0, 4);

        // 添加密码输入框
        TextField machineCodeField = new TextField();
        grid.add(machineCodeField, 1, 4);
        machineCodeField.setText(getMachineCode());
        machineCodeField.setEditable(false);

        // 添加登录按钮
        Button btn = new Button("登录");
        HBox hbBtn = new HBox(10);
        hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
        hbBtn.getChildren().add(btn);
        grid.add(hbBtn, 1, 5);

        // 添加提示信息
        final Text actiontarget = new Text();
        grid.add(actiontarget, 1, 6);

        // 设置按钮点击事件
        btn.setOnAction(e -> {
            btn.setDisable(true);
            if (!active){
                actiontarget.setFill(Color.FIREBRICK);
                actiontarget.setText("软件未激活！");
                btn.setDisable(false);
                return;
            }

            String username = userTextField.getText();
            String password = pwBox.getText();
            String codeFieldText = codeField.getText();
            if (StrUtil.isBlank(username)||StrUtil.isBlank(password)){
                actiontarget.setFill(Color.FIREBRICK);
                actiontarget.setText("账号密码或验证码为空！");
                btn.setDisable(false);
                return;
            }

            try{

                Map<String,String> param = new HashMap<>();
                param.put("username",username);
                param.put("password",password);
                param.put("code",codeFieldText);
                HttpResponse execute = HttpUtil.createPost(baseUrl + "/api/login")
                        .body(JSONUtil.toJsonStr(param))
                        .execute();

                JSONObject entries = JSONUtil.parseObj(execute.body());
                Integer code1 = entries.getInt("code");
                String message = entries.getStr("message");
                if (code1 == 200) {
                    actiontarget.setFill(Color.GREEN);
                    actiontarget.setText("登录成功！");
                    token = entries.getStr("data");
                    usernameStr = username;
                    stage.setScene(main);
                    stage.setTitle(stage.getTitle()+" "+usernameStr);

                }else{
                    actiontarget.setFill(Color.FIREBRICK);
                    actiontarget.setText("登录失败！ code:"+code1 + " message:"+message);
                    btn.setDisable(false);
                }
            }catch (Exception exception){
                actiontarget.setFill(Color.FIREBRICK);
                actiontarget.setText("登录失败！ error:"+exception.getMessage());
                btn.setDisable(false);
            }


        });
    }

    public void buyCk(){
        // 创建一个自定义弹窗
        ckDialog.setTitle("CK租用");
        GridPane gridPane = new GridPane();
        gridPane.setAlignment(Pos.CENTER);

        // 创建两个输入框

        Label numLabel = new Label("数量：");

        gridPane.add(numLabel,0,0,1,1);
        gridPane.add(ckNumField,1,0,1,1);


        // 将布局添加到弹窗中
        ckDialog.getDialogPane().setContent(gridPane);

        ckDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,ButtonType.CANCEL);
        ckDialog.setResultConverter(dialogButton -> {
            if (dialogButton == ButtonType.OK) {

                return ButtonType.OK;
            }
            return null;
        });


    }

    public void buySlink(){
        // 创建一个自定义弹窗
        slinkDialog.setTitle("购买店铺");
        GridPane gridPane = new GridPane();
        gridPane.setAlignment(Pos.CENTER);

        // 创建两个输入框

        Label codeLabel = new Label("数量：");

        gridPane.add(codeLabel,0,0,1,1);
        gridPane.add(slinkNumField,1,0,1,1);


        // 将布局添加到弹窗中
        slinkDialog.getDialogPane().setContent(gridPane);

        slinkDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,ButtonType.CANCEL);
        slinkDialog.setResultConverter(dialogButton -> {
            if (dialogButton == ButtonType.OK) {

                return ButtonType.OK;
            }
            return null;
        });
    }

    private String getMachineCode() {
        SystemInfo systemInfo = new SystemInfo();

        HardwareAbstractionLayer hardware = systemInfo.getHardware();
        CentralProcessor processor = hardware.getProcessor();
        ComputerSystem computerSystem = hardware.getComputerSystem();
        // 获取处理器ID作为机器码
        String processorID = processor.getProcessorIdentifier().getProcessorID();
        long total = hardware.getMemory().getTotal();
        String hardwareUUID = computerSystem.getHardwareUUID();
        String serialNumber = computerSystem.getSerialNumber();
        return DigestUtil.md5Hex(processorID+hardwareUUID+serialNumber+total);
    }

    public static void log(TextArea textArea,String log){
        textArea.appendText(DateUtil.now()+" "+log+"\n");
    }
}
